home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 41.zip
/
BS1 part 41
/
TEX files.adf
/
samples
/
primes.tex
< prev
next >
Wrap
Text File
|
1988-02-21
|
685b
|
25 lines
%
% This little program prints out prime numbers. From the
% TeXbook.
%
\newif\ifprime\newif\ifunknown
\newcount\p \newcount\d \newcount\a
\def\primes{\out{2}\out{3}\p=5
\loop\iftrue\printifprime\advance\p by2\repeat}
\def\printifprime{\testprimality
\ifprime\out{\number\p}\fi}
\def\testprimality{{\d=3\global\primetrue
\loop\trialdivision
\ifunknown\advance\d by2\repeat}}
\def\trialdivision{\a=\p
\divide\a by\d
\ifnum\a>\d\unknowntrue\else\unknownfalse\fi
\multiply\a by\d
\ifnum\a=\p \global\primefalse\unknownfalse\fi}
\def\out#1{\message{[#1]}}
%
% Now we invoke the program. Note, this is an infinite loop, so
% use *BREAK* to exit.
%
\primes